﻿var burl1 = "hangqing.ashx";
//burl1="http://172.28.1.72:8080";
var navigatorInfo=navigator.userAgent.toLowerCase();
var hqFlashIsSIE = (navigatorInfo.indexOf("msie 7.0") != -1 || navigatorInfo.indexOf("msie 8.0") != -1 || navigatorInfo.indexOf("msie 9.0") != -1) ? true : false;
//alert(hqFlashIsSIE);
var invForSIE = 0;
var intForSIE = 0;
function getUrl() {
    json = 100; t = 1;
    p = $("#hidP").val();
    c = $("#hidT").val();
    t = $("#hidTy").val();
    i = 1;
    id = $("#hidCode").val();
    return "?id=" + id + "&t=" + t + "&p=" + p + "&i=" + i + "&json=" + json + "&c=" + c;
}
function getData() {
//alert("getData");
    purl = burl1 + getUrl();
    //if (isNotIE) purl=purl+"&jsoncallback=?";
    //else {
        var ran=Math.random();
        purl=purl+"&ran="+ran.toString();
    //}
    //alert(purl);
    if (isReady)
        $.getJSON(purl, dataLoaded);
    else $.getJSON(purl, dataLoadedFirst);
}
function dataLoaded(data) {
//alert("dataLoaded");
    try {
        //alert(data);
        if (data == undefined) {
            dataLoadError();
            return;
        }
        chart1.refreshData("json", data);
    } catch (ex) {
        dataLoadError();
        //alert(ex.name + ":" + ex.message + ":" + ex.at + ":" + ex.text);
    }
}
function dataLoadedFirst(data) {
    try {
        if (data == undefined) {
            return;
        }
    //alert("dataLoadedFirst");

        firstData = data;
        if (hqFlashIsSIE) invForSIE = setInterval(forSIE, 500);
        else {
            if (chart1.refreshData("json", data)) {
                //alert("fasdf");
                invReady = setInterval(getData, 20 * 1000);
                isReady = true;
            }
            else {
                inv = setInterval(firstAdd, 500);
            }
        }
    } catch (ex) {
        //alert("err");
        inv = setInterval(firstAdd, 500);
        //dataLoadError();
        //alert(ex.name + ":" + ex.message + ":" + ex.at + ":" + ex.text);
    }
}
function forSIE() {
    try {
        if (intForSIE < 4) {
            chart1.refreshData("json", firstData);
            intForSIE++;
        }
        else {
            clearInterval(invForSIE);
            invReady = setInterval(getData, 20 * 1000);
            isReady = true;
        }
    } catch (ex) {
        //alert("forSIE.err");
    }
}
function firstAdd() {
    //alert("exefirstAdd");
    //if (chart1.refreshData("json", firstData)) {
    try{
        chart1.refreshData("json", firstData);
        //alert("clearFirst");
        if (inv) clearInterval(inv);
        invReady = setInterval(getData, 20*1000);
        isReady = true;
        //alert("fin");
    //}
     } catch (ex) {
        //alert("cant in");
     }
}

function dataLoadError() {
    //if (inv) clearInterval(getData, 5 * 1000);
    //$("#txtCode").val("");
    //alert("������ݳ���������������Ʊ���룡");
}